package com.hl.shifangzhiyu.web;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.hl.shifangzhiyu.pojo.ceyan;
import com.hl.shifangzhiyu.service.Impl.ceyanServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/ceyan")
public class ceyanController {
    @Autowired
    private ceyanServiceImpl ceyanService;
    @RequestMapping("/test")
    public int test(@RequestBody Map<String, Object> request) {
        List<String> answers = (List<String>) request.get("answer1");
        List<ceyan> list = ceyanService.select();
        int sum = 100;
        System.out.println("用户答案: " + answers);
        System.out.println("数据库查询结果: " + list);
        for (int i = 0; i < 10; i++) {
            if (list.get(i).getAnswer2().equals(answers.get(i))){
                sum-=10;
            }
        }
        System.out.println("最终得分: " + sum);
        return sum;
    }
    @RequestMapping("/getTiMu")
    public List<ceyan> getTiMu() {
        List<ceyan> list = ceyanService.getTiMu();
//        if (list == null) {
//            return Collections.emptyList(); // 避免返回 null
//        }
//        return list.stream()
//                .map(ceyan::getTimu)
//                .collect(Collectors.toList());
        return list;
    }
//    @RequestMapping("/getXuanXiang")
//    public List<ceyan> getXuanXiang() {
//        List<ceyan> list = ceyanService.getXuanXiang();
//        return list;
//    }
    }

